<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>个人资料</title>
<meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../../res/layui/css/layui.css"  media="all">
  <link rel="stylesheet" href="../../res/css/common/public.css"  media="all">
  <script src="../../res/js/common/jquery-1.11.2.min.js"></script>
  <script src="../../res/js/common/autocomplete.js"></script>
</head>
<body>
	<h3 style="margin: 20px 0px 10px 20px;color:#DD4B39;">我的资料</h3>
	<form class="layui-form" lay-filter="form-edit" style="width:500px;" id="myForm">
		<input type="hidden" name="adminId" class="layui-input">
		<input type="hidden" name="adminPictrue" class="layui-input">
		<div class="layui-form-item">
	    	<label class="layui-form-label">所属公司</label>
	    	<div class="layui-input-block">
	      		<input type="text" name="comName" disabled  class="layui-input layui-disabled">
	   		</div>
	  	</div>
	  	<div class="layui-form-item">
	    	<label class="layui-form-label">角色描述</label>
	    	<div class="layui-input-block">
	      		<input type="text" name="adminMsg" disabled  class="layui-input layui-disabled">
	   		</div>
	  	</div>
		<div class="layui-form-item">
	    	<label class="layui-form-label">用户名</label>
	    	<div class="layui-input-block">
	      		<input type="text" name="adminName" lay-verify="title"  autocomplete="off" class="layui-input">
	   		</div>
	  	</div>
	  	<div class="layui-form-item layui-row layui-col-xs12" >
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<textarea placeholder="请输入内容" class="layui-textarea userDesc"></textarea>
			</div>
		</div>
  		<div class="layui-form-item layui-upload ">
  		  <label class="layui-form-label">头像</label>
		  <button type="button" class="layui-btn layui-btn-primary" id="fileBtn">更换图片</button>
		  <button class="layui-btn" lay-submit="" lay-filter="formEdit">立即修改</button>
		  <div class="layui-upload-list" style="display: none">
		  	<label class="layui-form-label"></label>
		    <img class="layui-upload-img" id="pic" name="adminPictrue" style="width: 100px;height: 100px">
		    <p id="demoText"></p>
		  </div>
		</div>
	</form>
	<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 --> 
	<script src="../../res/layui/layui.all.js"></script> 
	<script type="text/javascript">
		layui.use(['form','upload'], function(){
	        var form = layui.form,upload = layui.upload;
	      	//普通图片上传
	        var uploadInst = upload.render({
	          elem: '#fileBtn'
	          ,url: '../../admin/upload.action'
	          ,before: function(obj){
	            //预读本地文件示例，不支持ie8
	            obj.preview(function(index, file, result){
	            	$(".layui-upload-list").css("display", "block");
	                $('#pic').attr('src', result); //图片链接（base64）
	            });
	          }
	          ,done: function(res){
	            //如果上传失败
	            if(res.code > 0){
	              return layer.msg('上传失败');
	            }
	            //上传成功
	            $("input[name=adminPictrue]").val(res.obj);
	          }
	          ,error: function(){
	            //演示失败状态，并实现重传
	            var demoText = $('#demoText');
	            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	            demoText.find('.demo-reload').on('click', function(){
	              uploadInst.upload();
	            });
	          }
	        });
	      	//查询个人资料信息
	        $.ajax({ url:"../../admin/getSession.action",
                type:'post',//method请求方式，get或者post
                async: false,//同步
                dataType:'json',//预期服务器返回的数据类型
                success:function(mes){//res为相应体,function为回调函数
            		autocomplete("myForm",mes);
            		$(".layui-upload-list").css("display", "block");
                },
                error:function(mes){
                	parent.location.href="../../pages/admin/login.html";
                }
            });
	        form.render();
	        
	        form.on('submit(formEdit)', function(data) {
		        $.ajax({ 
		        	url:"../../admin/update.action",
		        	 data: JSON.stringify(data.field),
	                type:'post',//method请求方式，get或者post
	                async: false,//同步
	                dataType:'json',//预期服务器返回的数据类型
	                contentType: "application/json; charset=utf-8",
	                success:function(mes){//res为相应体,function为回调函数
	                	layer.msg(mes.msg);
	            		if (mes.status=="1") {
            				$.post("../../admin/clearSession.action",null,function(mess){
            					 setTimeout(function(){
            						 parent.location.href="../../"+mes.url;
            			         }, 1500);
            				})
	            		}
	                }
	            });
            	return false;
	        });
		});
	    //ajax加载动画
	    $(function () {
            $.ajaxSetup({
                layerIndex:-1,
                beforeSend: function () {
                    this.layerIndex = layer.load(1, { shade: [0.8, '#ffffff'] });
                },
                complete: function () {
                    layer.close(this.layerIndex);
                },
                error: function () {
                    layer.alert('部分数据加载失败，可能会导致页面显示异常，请刷新后重试', {
                        skin: 'layui-layer-molv'
                       , closeBtn: 0
                       , shift: 4 //动画类型
                    });
                }
            });
        });
	</script>
</body>
</html>